package com.czl.module_storehouse.mvp.presenter;

import com.czl.base.data.bean.tengyun.BorrowBean;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.presenter.BasePresenter;
import com.czl.module_base.mvp.view.IView;
import com.czl.module_base.observer.AbsHandleSubscriber;
import com.czl.module_storehouse.bean.BorrowInfoBean;
import com.czl.module_storehouse.mvp.model.BorrowModel;

/**
 * @author by xubin,
 * @date on 2022/2/10.
 * PS: Not easy to write code, please indicate.
 */
public class BorrowPresenter extends BasePresenter<BorrowModel, IView> {
    public static final String TAG_BORROW_ADD_INFO = "borrow_add_info";

    public void getDealtBorrowList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getDealtBorrowList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<BorrowBean>>>(mView) {
            @Override
            public void onSuccess(HttpResponse<ListBean<BorrowBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getNeedDealtBorrowList(boolean refresh) {
        resetPageNo(refresh);
        doSubscribe(mModel.getNeedDealtBorrowList(mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<BorrowBean>>>(mView) {
            @Override
            public void onSuccess(HttpResponse<ListBean<BorrowBean>> httpResponse) {
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void addBorrowInfo(BorrowInfoBean borrowInfoBean) {
        doSubscribe3(mModel.addBorrowInfo(borrowInfoBean), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_BORROW_ADD_INFO);
                mView.showHttpResponse(httpResponse);
            }
        });
    }
}
